/**
 * @作者 田应平
 * @创建时间 2023-04-23 22:10
 * @QQ号码 444141300
 * @官网 http://www.fwtai.com
*/
;(function($){
  window.urlPrefix = 'http://127.0.0.1:910';
  window.webFiles = '/files';
  window.AppKey = {
    baseUri : window.location.origin,/**AppKey.baseUri*/
    iconDir : 'js/layer/theme/default/',/**AppKey.iconDir*/
    confirm : '确定',/**AppKey.confirm*/
    close : '关闭',/**AppKey.close*/
    submit : '提交',/**AppKey.submit*/
    cancel : '取消',/**AppKey.cancel*/
    title : "系统提示",
    msg_error : "哦!网络故障请<a href='javascript:;' onclick='if(self==top){window.location.reload();}else{top.location.reload();}' style='text-decoration:none;color:#3b8cff;outline:none;cursor:pointer;'>刷新</a>或稍后重试",/**连接服务器失败*/
    loginUrl : 'index.html',/**跳转到登录界面;用法:AppKey.loginUrl*/
    control : 'main.html',/**跳转到后台中心;用法:AppKey.control*/
    sysError : '系统出现错误',
    layerArea : '270px',/**AppKey.layerArea*/
    loadMsg : function(){
      var num = Math.random() * 10 + 1;/**随机生成1到10之间的数,包含1不包含10,即<=1 && =>9*/
      num = parseInt(num,10);
      if(num == 1){
        return '加载是件闹心事……';
      }else if(num == 2){
        return '感谢你的等待,请稍等……';
      }else if(num == 3){
        return '网络差,请稍等……';
      }else if(num == 4){
        return '正在载入数据……';
      }else if(num == 5){
        return '网络阻塞,努力加载中……';
      }else if(num == 6){
        return '服务器压力大,努力处理中……';
      }else if(num == 7){
        return '处理中,请稍等……';
      }else if(num == 8){
        return '数据正在赶来,请稍等……';
      }else{
        return '网络不给力,努力加载中……';
      }
    },
    code : {
      /**自定义code及msg*/
      code198 : 198,
      /**请求失败|操作失败*/
      code199 : 199,
      /**请求成功|操作成功*/
      code200 : 200,
      /**返回空值|暂无数据*/
      code201 : 201,
      /**请求协议参数不完整*/
      code202 : 202,
      /**密钥验证失败*/
      code203 : 203,
      /**系统出现错误*/
      code204 : 204,
      /**未登录或登录超时或token已失效*/
      code205 : 205,
      /**账号或密码不正确*/
      code206 : 206,
      /**非法操作!或你的账号已被删除,一般用于被迫强制退出登录*/
      code207 : 207,
      /**连接服务器失败*/
      code208 : 208,
      /**无权限操作*/
      code401 : 401
    },
    msg : {
      /**操作失败*/
      msg199 : '操作失败',
      /**操作成功*/
      msg200 : '操作成功',
      /**暂无数据*/
      msg201 : '暂无数据',
      /**参数不完整*/
      msg202 : '参数不完整',
      /**系统出现错误*/
      msg204 : '服务出现错误'
    }
  };
  window.winFn = {
    /**用JS获取地址栏参数且已编码的方法[采用正则表达式获取地址栏参数],用法:winFn.getParamURI('id');推荐*/
    getParamURI : function(key){
      var reg = new RegExp("(^|&)"+ key +"=([^&]*)(&|$)");
      var r = window.location.search.substring(1).match(reg);//search,查询?后面的参数,并匹配正则
      if(r!=null)return decodeURI(r[2]);return "";
    },
    /**赋值:winFn.setDomValue(dom,value);*/
    setDomValue : function(dom,value){
      try{
        if (value == null || value == '' || value == undefined || value == 'undefined'){
          $(dom).val('');
        } else {
          $(dom).val(value);
        }
      }catch(e){}
    },
    /**获取值(当第2个参数不为空时则处理预防xss功能):winFn.getDomValue(dom,true);if(value == null){}*/
    getDomValue : function(dom,xss){
      var v = $(dom).val();
      if(v == null || $.trim(v).length <= 0 || v == undefined)return null;
      if(v == '_') return null;
      if(xss){
        return $.trim(v).replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
      }
      return $.trim(v);
    },
    /**强制获取焦点:winFn.focus('#xx');*/
    focus : function(dom){
      $(dom).focus();
    },
    /**只适用于最顶级的级联的更改事件:winFn.onchange(dom,onchangeCall);可以在成功加载list数据之后再调用本方法;*/
    onchange : function(dom,onchangeCall){
      $(dom).on('change',function(){
        onchangeCall($(dom).val());
      });
    },
    /**禁用滚动条:winFn.overflowHidden();*/
    overflowHidden : function(){
      $("body").eq(0).css("overflow","hidden");
    },
    /**启用滚动条:winFn.overflowAuto();*/
    overflowAuto : function(){
      $("body").eq(0).css("overflow","auto");
    },
    /**刷新验证码:winFn.refreshCode(domImage,"imgCode");其中imgCode是获取验证码的url,即标签为<img src="imgCode">*/
    refreshCode : function(domImage,url){
      $(domImage).attr("src",urlPrefix + url+"?date="+new Date().getTime());
    },
    /**单个元素或节点赋值,不含html:winFn.setText(dom,value);*/
    setText : function(dom,value){
      $(dom).text(value);
    },
    /**获取数组的长度:winFn.arrLength(arr,flag);winFn.arrLength(arr);*/
    arrLength : function(arr,flag){
      if(flag == null || flag == '' || flag == undefined)flag = ",";
      if(arr == null || arr == '')return 0;
      return arr.split(flag).length;
    },
    /**以复选框的选择而全选否则以取消而全部取消选择;局部areaDom块,为空时是整个页面;winFn.checkDom(checkboxObj,checkboxName,areaDom);*/
    checkDom : function(checkboxObj,checkboxName,areaDom){
      $(checkboxObj).on("change", function(){
        var _self = this;
        if(areaDom != null && areaDom != ''){
          $(areaDom + " input[name='"+checkboxName+"']").each(function(){
            this.checked = _self.checked;
          });
        }else{
          $("input[name='"+checkboxName+"']").each(function(){
            this.checked = _self.checked;
          });
        }
      });
    },
    /**以复选框的选中或取消对应的操作:winFn.checkFn(checkboxObj,on,off);*/
    checkFn : function(checkboxObj,on,off){
      $(checkboxObj).on("change", function(){
        var _self = this;
        if (_self.checked){
          on();
        } else {
          off();
        }
      });
    },
    /**以复选框的选中显示input或取消隐藏input的操作,原生态的input输入框默认是隐藏:winFn.checkOnOff(checkboxObj,inputDom,on,off);*/
    checkOnOff : function(checkboxObj,inputDom,on,off){
      $(checkboxObj).on("change",function(){
        var _self = this;
        if (_self.checked){
          $(inputDom).css({"visibility":"visible"});
          $(inputDom).show();
          on();
        } else {
          $(inputDom).css({"visibility":"hidden"});
          $(inputDom).hide();
          off();
        }
      });
    },
    /**获取浏览器可视区域宽度,兼容主流浏览器:winFn.fnGetWidth();*/
    fnGetWidth : function(){
      var viewportwidth = 0;
      if (typeof window.innerWidth != 'undefined'){
        viewportwidth = window.innerWidth;
      }else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
        viewportwidth = document.documentElement.clientWidth;
      }else {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
      }
      return viewportwidth;
    },
    /**获取浏览器可视区域高度,兼容主流浏览器:winFn.fnGetHeight();*/
    fnGetHeight : function(){
      var viewportheight = 0;
      if (typeof window.innerWidth != 'undefined'){
        viewportheight = window.innerHeight;
      }else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
        viewportheight = document.documentElement.clientHeight;
      }else {
        viewportheight = document.getElementsByTagName('body')[0].clientHeight;
      }
      return viewportheight;
    },
    /**在当前页打开页面,适用于下载或导出数据,如有参数拼装在url里:winFn.winOpen(url);*/
    winOpen : function(url){
      if(self==top){
        window.location.href = url;
      }else{
        top.location.href = url;
      }
    },
    //跳转新页面的解决方案,解决缓存'?refresh='new Date().getTime()
    jumpPage : function(domId,url){
      $('#'+domId).attr('href',url);//其中的html--> <a href="javascript:;" target="_blank" style="display:none" id="jumpAuth"></a>
      document.getElementById(domId).click();//原生JS不受影响
    },
    /**下载文件,不带token,含文件名的参数拼装在url里:用法:winFn.downloadFile(url);layerFn.alert('已进入后台处理,请耐心等待,处理完成将会自动下载!',AppKey.code.code200);*/
    downloadFile : function(url){
      $("<form method='POST' action='" + urlPrefix + url + "'></form>").appendTo("body").submit().remove();
    },
    /**按Enter回车键事件:winFn.Enter(fn);*/
    Enter : function(fn){
      opts.event({
        code : 13,
        fn : function(){
          if (fn != null && fn !=''){
            fn();
          }
        }
      });
    },
    /**IE低版本支持默认现实提示信息:winFn.iePlaceholder();*/
    iePlaceholder : function(){
      $('input,textarea').placeholder({customClass:'ie_placeholder'});
    },
    /**通过生成随机数生成uuid唯一值:winFn.getUuid();*/
    getUuid : function(){
      //随机生成4个字符串
      function rdmCode(){
        return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
      }
      return rdmCode()+rdmCode()+rdmCode()+rdmCode()+rdmCode()+rdmCode()+rdmCode()+rdmCode();
    },
    //获取屏幕的属性(分辨率|屏幕可用尺寸|浏览器尺寸|网页尺寸);用法：winFn.getDpiSize().screenWidth;
    getDpiSize : function(){
      return {
        screenWidth: screen.width,//屏幕分辨率宽
        screenHeight: screen.height,//屏幕分辨率高
        avaiWidth: screen.availWidth,//屏幕可用尺寸宽
        avaiHeight: screen.availHeight,//屏幕可用尺寸高
        browserWidth: window.innerWidth,//浏览器尺寸宽
        browserHeight: window.innerHeight,//浏览器尺寸高
        pageWidth: document.body.clientWidth,//网页尺寸宽
        pageHeight: document.body.clientHeight//网页尺寸高
      }
    }
  };
  /**依赖jQuery*/
  window.verifyFn = {
    /**验证是否是正整数,是返回true,否则返回false:verifyFn.checkIsNum(value);*/
    checkIsNum : function(value){
      var reg = /^[0-9]*[1-9][0-9]*$/;
      return reg.test(value);
    },
    //仅适用于input=text的输入框非空验证为空时左右抖动,带回调 if(verifyFn.inputEmpty('#dom|.dom'))return;
    inputEmpty : function(dom,callback){
      var value = winFn.getDomValue(dom);
      if(value == null){
        var duration = 300;
        $(dom).shake(2,10,duration);
        $(dom).focus();
        if(callback){
          setTimeout(function(){
            callback(dom);
          },duration);
        }
        return true;
      }
      return false;
    },
    /**验证是否为空:verifyFn.isEmpty(value);*/
    isEmpty : function(object){
      if(typeof object == 'function'){
        if(object == null || object == '' || object == undefined || object == 'undefined')return true;
      }
      if (object != null && object != ''){
        if(object == 'undefined' || object == 'UNDEFINED')return true;
      }
      if(object == null || object == undefined || object == '')return true;
      if($.trim(object).length > 0 && $.trim(object) == 'null')return true;
      if($.trim(object).length > 0 && $.trim(object) == 'NULL')return true;
      if(object.length == 0)return true;
      if($.trim(object).length <= 0)return true;
      if($.trim(object) == '')return true;
      return false;
    },
    /**验证是否为email格式:verifyFn.isEmail(value);*/
    isEmail : function(value){
      if (/^([\w\.\-])+\@\w+(\.[a-zA-Z]+)+$/.test(value))return true;
      return false;
    },
    /**判断这两个数据是否不相等，区分大小写,不相等返回true:verifyFn.checkEqual(value1,value2);*/
    checkEqual : function(value1,value2){
      if(value1 != value2){
        return true;
      }else {
        return false;
      }
    },
    /**检查是否支持对应的浏览器:verifyFn.checkBrowser(hint,target);*/
    checkBrowser : function(hint,target){
      var ua = navigator.userAgent.toLowerCase(), s, app = {}, url, host = window.location.host;
      (s = ua.match(/msie ([\d.]+)/)) ? app.ie = s[1] : (s = ua.match(/firefox\/([\d.]+)/)) ? app.firefox = s[1] : (s = ua.match(/chrome\/([\d.]+)/)) ? app.chrome = s[1] : (s = ua.match(/opera.([\d.]+)/)) ? app.opera = s[1] : (s = ua.match(/version\/([\d.]+).*safari/)) ? app.safari = s[1] : 0;
      var bro = false;
      if (app.ie){
        bro = true;// 如果浏览器为IE则跳转到;
      } else if (app.chrome){
        bro = false;// 如果浏览器为Chrome则跳转到相对链接html/
      } else if (app.opera){
        bro = false;// 如果浏览器为Opera则则跳转到相对链接/html/
      } else if (app.firefox){
        bro = false;// 如果浏览器为firefox则跳转到上级目录/
      } else if (app.safari){
        bro = true;// 如果浏览器为Safari则跳转到当前域名
      } else {
        bro = true;// 其他浏览器打开跳转到空白页面;
      }
      if (bro){
        document.location.href = hint;
      }else {
        document.location.href = target;
      }
    }
  };
  window.layerFn = {
    /**确认操作,且取消按钮和右上角具有同一事件:layerFn.confirm(msg,function(){},function(){});如果需要调用到第2个方法则第1个方法是不能少的,写function(){}即可*/
    confirm : function (msg,fnVerify,fnCancel){
      msg = verifyFn.isEmpty(msg)?"确定要操作吗?":msg;
      var exitIndex = top.layer.confirm('<div style="color:red;"><img src="'+AppKey.iconDir+'help_icon.png" style="vertical-align:middle;margin-right:3px;"/>'+msg+'</div>',{
        title : AppKey.title,
        area : AppKey.layerArea,
        btn : [AppKey.confirm,AppKey.cancel],
        cancel : fnCancel,
      },function(index){
        layerFn.closeIndex(index);
        if(fnVerify){fnVerify();}
      },function(index){
        layerFn.closeIndex(index);
        if(fnCancel){fnCancel();}
      });
      layerFn.EscLayer(exitIndex);
      return exitIndex;
    },
    /**不带正在加载提示信息POST请求远程数据,layerFn.ajaxPost(url,params,succeed);*/
    ajaxPost : function(url,params,succeed){
      postRow(url,params,function(data){
        if(data.code == AppKey.code.code200){
          succeed(data);
        }else{
          layerFn.alert(data.msg,data.code);
        }
      });
    },
    /**不带正在加载提示信息GET请求远程数据,layerFn.ajaxGet(url,params,succeed);*/
    ajaxGet : function(url,params,succeed){
      getQuery(url,params,function(data){
        if(data.code == AppKey.code.code200){
          succeed(data);
        }else{
          layerFn.alert(data.msg,data.code);
        }
      });
    },
    /**不推荐使用,不带正在加载提示信息GET请求远程数据,未处理code=401的情况需要自行处理,但已处理code为205业务,当然在调用时也可以再处理,如：text(data.msg);layerFn.ajaxGetResult(url,params,succeed);*/
    ajaxGetResult : function(url,params,succeed){
      getQuery(url,params,function(data){
        succeed(data);
      });
    },
    /**带动画的ajax的POST提交,仅适用于增、删、改操作且已做请求失败的处理;layerFn.submit(url,params,fnSuccess);成功时才关闭对话框,所以不需要处理失败的回调及code为200以外的数据处理*/
    submit : function(url,params,fnSuccess){
      postRowHint(url,params,function(data){
        if (data.code == AppKey.code.code200){
          fnSuccess(data);
        }else{
          layerFn.alert(data.msg,data.code);
        }
      });
    },
    /**带动画的Post请求,自行处理失败的回调及code为200及以外的数据处理,已处理code=205*/
    submitResult : function(url,params,callbak){
      postAjaxHint(url,params,function(data){
        callbak(data);
      });
    },
    /**带动画的ajax的POST提交,仅适用于增、删、改操作且已做请求失败的处理;layerFn.submitRestful(url,fnSuccess);成功时才关闭对话框,所以不需要处理失败的回调及code为200以外的数据处理*/
    submitRestful : function(url,fnSuccess){
      postRowHint(url,{},function(data){
        if (data.code == AppKey.code.code200){
          fnSuccess(data);
        }else{
          layerFn.alert(data.msg,data.code);
        }
      });
    },
    /**带动画的ajax的GET请求,仅适用于查询操作且已做请求失败的处理;layerFn.queryGetHint(url,params,fnSuccess);成功时才关闭对话框,所以不需要处理失败的回调及code为200以外的数据处理*/
    queryGetHint : function(url,params,fnSuccess){
      getQueryHint(url,params,function(data){
        if (data.code == AppKey.code.code200){
          fnSuccess(data);
        }else{
          layerFn.alert(data.msg,data.code);
        }
      });
    },
    /**需要自行处理结果的动画的GET请求,仅适用于查询操作且未做code的任何情况,但已处理code为205业务,当然在调用时也可以再处理,需要调用者自行处理code的值为200,201,401,19x结果;layerFn.queryGetHintResult(url,params,callbak);*/
    queryGetHintResult : function(url,params,callbak){
      getQueryHint(url,params,function(data){
        callbak(data);
      });
    },
    /**以id查询单条数据的全部字段信息,适用于存在就查看或编辑否则就添加,带正在加载的提示信息,无需处理失败的回调及code为200及201以外的数据处理,用法:layerFn.queryByIdHint(url,id,function(data){编辑},function(data){添加});*/
    queryByIdHint : function(url,id,fnSuccess,fnEmpty){
      getQueryHint(url,{id:id},function(data){
        if(data.code == AppKey.code.code200){
          fnSuccess(data);
        }else if(data.code == AppKey.code.code201){
          if(fnEmpty != null && fnEmpty != ''){
            fnEmpty(data);
          }else{
            layerFn.alert(data.msg,data.code);
          }
        }else{
          layerFn.alert(data.msg,data.code);
        }
      });
    },
    /*用法:self.layerIndex = layerFn.loading('正在处理……');可选值:('操作中,请稍候……','196px');|('正在处理……','179px');|*/
    loading : function(msg,width){
      msg = (msg == null || msg == '' || msg == undefined)?'处理中,请稍候……':msg;
      width = (width == null || width == '') ? '196px' : width;
      return top.layer.msg(msg,{icon:16,time:-1,shade:[0.3,'#000'],area:width});
    },
    closeIndex : function(index){
      top.layer.close(index);
    },
    closedAll : function(){
      top.layer.closeAll();
    },
    //自定义layer样式
    layerAlert : function(msg,closed){
      var imagerUrl = AppKey.iconDir+'success.png';
      var content = '<div style="height:50px;line-height:50px;padding:0 20px;width:auto;"><img src='+imagerUrl+' style="vertical-align:middle;margin-right:3px;"/>'+msg+'</div>';
      return layer.open({
        type : 1,
        title : false,
        content : content,
        closeBtn : 0,
        shade : 0,
        resize : false,
        move : false,
        btn : false,
        time : 2100,
        end : closed
      });
    },
    /*用法:layerFn.connectFailure(msg);有可能是url的前面添加的前缀导致的*/
    connectFailure : function(msg){
      msg = (msg == null || msg == '' || msg == undefined)?'连接服务器失败,请稍后重试':msg;
      this.alert(msg,AppKey.code.code199);
    },
    handleResult : function(msg,code,time){
      msg = (msg == null || msg == '' || msg == undefined)?'操作错误':msg;
      code = parseInt(code);
      var imagerUrl = AppKey.iconDir+'warn.png';
      var img_style = '"vertical-align:middle;margin-right:3px;"';
      var content = '<div>'+msg+'</div>';
      switch(code){
        case AppKey.code.code200:
          msg = verifyFn.isEmpty(msg)?"操作成功":msg;
          imagerUrl = AppKey.iconDir+'success.png';
          content = '<div><img src='+imagerUrl+' style='+img_style+'/>'+msg+'</div>';
          break;
        case AppKey.code.code204:
          msg = verifyFn.isEmpty(msg)?AppKey.sysError:msg;
          imagerUrl = AppKey.iconDir+'error.png';
          content = '<div><img src='+imagerUrl+' style='+img_style+'/>'+msg+'</div>';
          break;
        default:
          content = '<div><img src='+imagerUrl+' style='+img_style+'/>'+msg+'</div>';
          break;
      }
      time = (time == null || time == '') ? 2500 : time;
      var exitIndex = top.layer.alert(content,{title:AppKey.title,closeBtn:1,shade:0,time:time,anim:2,offset:'rb',btn:null,});
      layerFn.EscLayer(exitIndex);
    },
    handleTop : function(msg,code){
      msg = (msg == null || msg == '' || msg == undefined)?'警告':msg;
      if(!isNaN(code)){
        var imagerUrl = AppKey.iconDir+'warn.png';
        var img_style = '"vertical-align:middle;margin-right:3px;"';
        msg = '<div><img src='+imagerUrl+' style='+img_style+'/>'+msg+'</div>';
      }
      return top.layer.alert(msg,{title:false,closeBtn:0,shade: 0,btn:false,time:2000,offset: 't'});
    },
    handleClose : function(msg,code){
      msg = (msg == null || msg == '' || msg == undefined)?'警告':msg;
      if(!isNaN(code)){
        var imagerUrl = AppKey.iconDir+'warn.png';
        var img_style = '"vertical-align:middle;margin-right:3px;"';
        msg = '<div><img src='+imagerUrl+' style='+img_style+'/>'+msg+'</div>';
      }
      var exitIndex = top.layer.alert(msg,{title:AppKey.title,move:false,btn:false,area : ['250px','auto']});
      layerFn.EscLayer(exitIndex);
    },
    /**按Esc键关闭layer对话框或仅用于查看的layer层:layerFn.EscLayer(index);*/
    EscLayer : function(index){
      opts.event({
        code : 27,
        fn : function(){
          layerFn.closeIndex(index);
          index = null;
        }
      });
    },
    /**用于编辑或添加,调用方法:layerFn.addOrEdit(title,domDivId,[width,height],function(layerIndex,layero){},btn3,btn3Call);第5个参数是第3个按钮名称[支持html],第6个参数是5个按钮参数是事件;不含右上角关闭的事件*/
    addOrEdit : function(title,domDivId,area,closedCall,btn3,btn3Call){
      var btns = (btn3 == null || btn3 == '') ? [AppKey.submit,AppKey.cancel] : [AppKey.submit,AppKey.cancel,btn3];
      return layer.open({
        type : 1,
        title : title,
        content : $(domDivId),//这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
        area : area,
        resize : false,
        btn : btns,
        yes : function(index,layero){
          if (closedCall != null && closedCall != ''){
            closedCall(index,layero);
          }
        },
        btn3 : function(index,layero){
          if (btn3Call != null && btn3Call != '' && btn3 != null && btn3 != ''){
            btn3Call(index,layero);
          }
          return false;
        }
      });
    },
    /**用于编辑或添加,带弹出成功后回调；调用方法:layerFn.addOrEditCallBack(title,domDivId,[width,height],function(layerIndex,layero){},function(){弹出成功后回调},btn3,btn3Call);第5个参数是第3个按钮名称[支持html],第6个参数是5个按钮参数是事件;不含右上角关闭的事件*/
    addOrEditCallBack : function(title,domDivId,area,closedCall,succeed,btn3,btn3Call){
      var btns = (btn3 == null || btn3 == '') ? [AppKey.submit,AppKey.cancel] : [AppKey.submit,AppKey.cancel,btn3];
      return layer.open({
        type : 1,
        title : title,
        content : $(domDivId),//这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
        success: function(layero, index){
          if(succeed){
            succeed(layero,index);
          }
        },
        area : area,
        resize : false,
        btn : btns,
        yes : function(index,layero){
          if (closedCall != null && closedCall != ''){
            closedCall(index,layero);
          }
        },
        btn3 : function(index,layero){
          if (btn3Call != null && btn3Call != '' && btn3 != null && btn3 != ''){
            btn3Call(index,layero);
          }
          return false;
        }
      });
    },
    /**含2个按钮2个回调,一个右上角的关闭回调,用于编辑或添加,调用方法:layerFn.addOrEditEvent(title,domDivId,['width_px','height_px'],function(layerIndex,layero){},function(layerIndex,layero){},function(){});第5个参数是第2个按钮的事件;cancelCall是右上角关闭的事件*/
    addOrEditEvent : function(title,domDivId,area,closedCall,fn2Call,cancelCall){
      return layer.open({
        type : 1,
        title : title,
        content : $(domDivId),
        area : area,
        resize : false,
        btn : [AppKey.submit,AppKey.cancel],
        yes : function(index,layero){
          if (closedCall != null && closedCall != ''){
            closedCall(index,layero);
          }
        },
        btn2: function(index,layero){
          if (fn2Call != null && fn2Call != ''){
            fn2Call(index,layero);
          }
        },
        cancel: function(){
          if (cancelCall != null && cancelCall != ''){
            cancelCall();
          }
        }
      });
    },
    /*弹出输入框*/
    dialogPrompt : function(){
      return layer.prompt({
        formType: 2,
        title: '请输入数据',
        value:'',
        area: ['400px','250px'],
        btnAlign: 'c',
        btn: ['通过','不通过','取消'],
        yes: function(index, layero){
          var value = $('#layui-layer'+index + " .layui-layer-input").val();
          if (!value) {
            return false;
          }
          layer.close(index);
          console.log('通过',value);
        },
        btn2 : function(index, layero){
          var value = $('#layui-layer'+index + " .layui-layer-input").val();
          if (!value) {
            return false;
          }
          layer.close(index);
          console.log('不通过',value);
        },
        btn3 : function(index){
          layer.close(index);
          console.log('取消');
        },
        cancel: function(){
          console.log('关闭');
        }
      });
    },
    /**用于编辑|添加|查看的居中的弹出框:layerFn.winDom(title,domDivId,[width,height],function(layerIndex,layero){},btn);最后一个参数btn不为空时则是单个按钮,且callback可以为null*/
    winDom : function(title,domDivId,area,callback,btn){
      return top.layer.alert('',{
        shade : 0.3,
        type : 1,
        title : title,
        content : $(domDivId),//这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
        btnAlign: 'c',
        closeBtn: 1,
        resize : false,
        area : area,
        btn : !btn ? [AppKey.submit,AppKey.cancel]:[btn],
        yes : !btn ? function(index,layero){
          callback(index,layero);
        }:''
      });
    },
    /**用于编辑|添加|查看的右边Right的弹出框,但是IE8不兼容:layerFn.winRUrl('编辑','page?page=edit','1000px',function(layerIndex,layero){},btn);最后一个参数不为空时则是单个按钮*/
    winRUrl : function(title,url,width,callback,btn){
      return top.layer.alert('',{
        offset: 'rt',
        shade : 0.3,
        anim : 2,
        type : 2,
        title : title,
        content : url,
        btnAlign: 'c',
        closeBtn: 0,
        resize : false,
        move: false,
        area : [width,'100%'],
        btn : !btn ? [AppKey.submit,AppKey.cancel]:[btn],
        yes : !btn ? function(index,layero){
          callback(index,layero);
        }:''
      });
    },
    /**用于编辑|添加|查看的右边Right的弹出框:layerFn.winRDom(title,domDivId,'1000px',function(layerIndex,layero){},btn);最后一个参数btn不为空时则是单个按钮,且callback可以为null*/
    winRDom : function(title,domDivId,width,callback,btn){
      return top.layer.alert('',{
        offset: 'rt',
        shade : 0.3,
        anim : 2,
        type : 1,
        title : title,
        content : $(domDivId),//这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
        btnAlign: 'c',
        closeBtn: 0,
        resize : false,
        move: false,
        area : [width,'100%'],
        btn : !btn ? [AppKey.submit,AppKey.cancel]:[btn],
        yes : !btn ? function(index,layero){
          callback(index,layero);
        }:''
      });
    },
    /**适用于查看,带自动关闭的,当time为空或为0时是不会自动关闭;layerFn.viewDialog(title,domDivId,[width,height],time);*/
    viewDialog : function(title,domDivId,area,time){
      time = (time == null || time == '') ? 0 : time;
      return top.layer.open({
        type : 1,
        title : title,
        content : $(domDivId),//这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
        area : area,
        btn : [AppKey.close],
        time : time,
        resize : false
      });
    },
    /**仅查看且带关闭事件*/
    viewCloseEvent : function(title,domDivId,area,close){
      return top.layer.open({
        type : 1,
        title : title,
        content : $(domDivId),
        area : area,
        btn : [AppKey.close],
        yes : function(index,layero){
          layer.close(index);
          if (close != null && close != ''){
            close(index,layero);
          }
        },
        cancel: function(index,layero){
          if (close != null && close != ''){
            close(index,layero);
          }
        },
        resize : false
      });
    },
    /**提示框:layerFn.tips('#id或者.class','请填写内容');*/
    tips : function(dom,msg){
      layer.tips(msg,dom,{
        tips: [2,'#459df5']//2;4
      });
    },
    /*用法:layerFn.prompt(function(value,index){},'请输入解锁密码');*/
    prompt : function(callback,title){
      title = (title == null || title =='') ? "请输入内容" : title;
      layer.prompt({title:title,move: false},function(value,index){
        layer.close(index);
        callback(value,index);
      });
    },
    /**居中偏上top;layerFn.showTop(msg,AppKey.code.code200);*/
    showTop : function(msg,code){
      code = parseInt(code);
      var imagerUrl = AppKey.iconDir+'icon_ok.png';
      switch (code){
        case AppKey.code.code200:
          msg = verifyFn.isEmpty(msg)?"操作成功":msg;
          break;
        case AppKey.code.code199:
          msg = verifyFn.isEmpty(msg)?"操作失败":msg;
          imagerUrl = AppKey.iconDir+'warn.png';
          break;
        default:
          msg = verifyFn.isEmpty(msg)?"操作有误":msg;
          imagerUrl = AppKey.iconDir+'error.png';
          break;
      }
      layer.open({
        type : 1,
        title : false,
        shade : 0, //遮罩透明度
        closeBtn : 0, //不显示关闭按钮
        area : ['auto', '40px'],
        offset : '8px',
        content : '<div style="line-height:40px;height:40px;padding-left:16px;padding-right:16px;display:inline-block;"><img src='+imagerUrl+' style="margin-bottom:2px;margin-right:4px;"/>'+msg+'</div>',
        time : 1500
      });
    },
    /**单个按钮的提示框,默认有270px的宽度,不带回调事件:layerFn.alert(msg,code);code不为空且值为[AppKey.code.code198,199,200,201,202,203,204,205,206,207]之一时显示图标*/
    alert : function(msg,code,width){
      if(code == null || code == ''){
        opts.dialog({msg : msg});
      }else{
        opts.dialog({msg : msg,code:code,width:width});
      }
    },
    /**单个按钮的提示框,默认有270px的宽度,按＇确定＇回调事件,code可选,默认为199*/
    alertCallback : function(msg,callback,code){
      if(code == null || code == undefined || code == ''){
        opts.dialog({msg : msg,code:AppKey.code.code199,callback:callback});
      }else{
        opts.dialog({msg : msg,code:code,callback:callback});
      }
    },
    /**提示输入框,layerFn.inputValue(function(value){});*/
    inputValue : function(callBack){
      layer.prompt({title:'请输入'},function(value,index){
        layer.close(index);
        callBack(value);
      });
    },
    /**对话框关闭事件,不管按确定按钮或右上角的按钮都会触发事件:layerFn.closeEvent(msg,code,function(){});*/
    closeEvent : function (msg,code,callBack){
      msg = verifyFn.isEmpty(msg)?"操作有误":msg;
      code = parseInt(code);
      var imagerUrl = AppKey.iconDir+'warn.png';
      var img_style = '"vertical-align:middle;margin-right:3px;"';
      var content = '<div><img src='+imagerUrl+' style='+img_style+'/>'+msg+'</div>';
      switch(code){
        case AppKey.code.code200:
          msg = verifyFn.isEmpty(msg)?"操作成功":msg;
          imagerUrl = AppKey.iconDir+'success.png';
          content = '<div><img src='+imagerUrl+' style='+img_style+'/>'+msg+'</div>';
          break;
        case AppKey.code.code204:
        case AppKey.code.code205:
        case AppKey.code.code207:
          msg = verifyFn.isEmpty(msg)?AppKey.sysError:msg;
          imagerUrl = AppKey.iconDir+'error.png';
          content = '<div><img src='+imagerUrl+' style='+img_style+'/>'+msg+'</div>';
          break;
        default:
          break;
      }
      return top.layer.alert(content,{
        title : AppKey.title,
        btn : [AppKey.confirm],
        area : AppKey.layerArea,
        cancel : callBack,
      },function(index){
        layerFn.closeIndex(index);
        if(callBack != null && callBack != ''){
          callBack();
        }
      });
    },
    /*表单提交,表单+文件异步提交,后端不能用@RequestBody接收!!!,用法:*/
    formSubmit : function(url,formData,succeed,error){
      var layerIndex = layerFn.loading('正在处理……');
      $.ajax({
        url : urlPrefix + url,
        type : "POST",
        data : formData,
        contentType : false,
        processData : false,
        headers : {'accessToken': sessionStorage.getItem('accessToken') || ''},
        dataType : "json",
        success : function(data){
          layerFn.closeIndex(layerIndex);
          if(data.code == AppKey.code.code200){
            succeed(data);
          }else{
            layerFn.alert(data.msg,data.code);
          }
        },
        error : function (err){
          layerFn.closeIndex(layerIndex);
          if(error){
            error(err);
          }else{
            layerFn.connectFailure();
          }
        },
        complete : function(response,status){
          layerFn.closeIndex(layerIndex);
          ajaxComplete(response.responseJSON);
        }
      });
    }
  };
  /**插件定义配置*/
  window.opts = {
    /**layer单个按钮的提示框,不带回调事件:opts.dialog(options);不带code就不显示图标;*/
    dialog : function (options){
      var title = options.title || AppKey.title;
      var msg = options.msg || '操作有误';
      var code = options.code || null;
      var width = options.width || AppKey.layerArea;
      var callback = options.callback || null;//点击yes'确定'按钮回调
      code = parseInt(code);
      var imagerUrl = AppKey.iconDir+'warn.png';
      var img_style = '"vertical-align:middle;margin-right:3px;"';
      var content = '<div>'+msg+'</div>';
      switch(code){
        case AppKey.code.code200:
          msg = verifyFn.isEmpty(msg)?"操作成功":msg;
          imagerUrl = AppKey.iconDir+'success.png';
          content = '<div><img src='+imagerUrl+' style='+img_style+'/>'+msg+'</div>';
          break;
        case AppKey.code.code204:
          msg = verifyFn.isEmpty(msg)?AppKey.sysError:msg;
          imagerUrl = AppKey.iconDir+'error.png';
          content = '<div><img src='+imagerUrl+' style='+img_style+'/>'+msg+'</div>';
          break;
        default:
          content = '<div><img src='+imagerUrl+' style='+img_style+'/>'+msg+'</div>';
          break;
      }
      if(isNaN(code)){
        content = msg;
      }
      var exitIndex = top.layer.alert(content,{
        title : title,
        area : width,
        btn : [AppKey.confirm],
        yes : function(){
          if(callback){
            callback();
          }
          top.layer.close(exitIndex);
        },
        cancel : function(){
          if(callback){
            callback();
          }
        }
      });
      layerFn.EscLayer(exitIndex);
      return exitIndex;
    },
    /**按键盘监听事件回调:opts.event({code:27,fn:function(){}});*/
    event : function(options){
      var code = options.code || null;
      var fn = options.fn || null;
      $(document).keydown(function(e){
        if(e.keyCode == code){
          if (fn !=null && fn != undefined){
            fn();
          }
        }
      });
    },
  };
  /**alert('好的,谢谢!',function(){alert('嗯,再见!')}),可以加 area 宽高度的 */
  window.alert = function(msg,callback){
    var al_t = (self==top)?parent:window;
    return al_t.layer.alert(msg,{
      title : AppKey.title,
      btn : [AppKey.confirm],
      cancel : function(index,layero){
        al_t.layer.close(index);
        if(callback != null && callback != ''){
          callback();
        }
      }
    },function (index) {
      al_t.layer.close(index);
      if(callback != null && callback != ''){
        callback();
      }
    });
  };
  /**confirm('你好,需要服务吗?',function() {alert('好的,谢谢!',function(){alert('嗯,再见!')})});*/
  window.confirm = function(msg,callback){
    var conf_m = (self==top)?parent:window;
    return conf_m.layer.confirm(msg,{
        title : AppKey.title,
        btn : [AppKey.confirm,AppKey.cancel],
        area : 'auto'
      },
      function(index){
        if(typeof(callback) === "function"){
          conf_m.layer.close(index);
          callback("ok");
        }
      }
    );
  };
  //不带请求动画少后面两个参数,一般用于select查询方法
  function getQuery(url,params,success){
    ajaxRequestGet(url,params,null,function(data){
      success(data);
    });
  }
  //含带请求动画,方法beforeSend不为空,一般用于select查询方法
  function getQueryHint(url,params,success,msg){
    msg = (msg == null || msg == '') ? "正在处理……" : msg;
    self.layerIndex = layerFn.loading(msg);
    ajaxRequestGet(url,params,function(request){},function(data){
      layerFn.closeIndex(self.layerIndex);
      success(data);
    },function(response,err){
      layerFn.closeIndex(self.layerIndex);
    },function(){
      layerFn.closeIndex(self.layerIndex);
    });
  }
  //不带请求动画少后面两个参数,一般用于insert,update,delete方法
  function postRow(url,params,success){
    ajaxRequestPost(url,params,null,function(data){
      success(data);
    });
  }
  //有带请求动画,方法beforeSend不为空,一般用于insert,update,delete方法
  function postRowHint(url,params,success,msg){
    msg = (msg == null || msg == '') ? "正在处理……" : msg;
    self.layerIndex = layerFn.loading(msg);
    ajaxRequestPost(url,params,function(request){},function(data){
      layerFn.closeIndex(self.layerIndex);
      success(data);
    },function(response,err){
      layerFn.closeIndex(self.layerIndex);
    },function(){
      layerFn.closeIndex(self.layerIndex);
    });
  }
  //有带请求动画,方法beforeSend不为空,一般用于insert,update,delete方法
  function postAjaxHint(url,params,success){
    self.layerIndex = layerFn.loading('正在处理……');
    ajaxRequestPost(url,params,function(request){},function(data){
      layerFn.closeIndex(self.layerIndex);
      success(data);
    },function(response,err){
      layerFn.closeIndex(self.layerIndex);
    },function(){
      layerFn.closeIndex(self.layerIndex);
    });
  }
  //后面的两个参数error,complete是给带请求动画用的
  function ajaxRequestGet(url,params,beforeSend,success,error,complete){
    ajaxGet(url,params,function(request){
      if(beforeSend){
        beforeSend(request);
      }
    },function(data){
      var bl = layerFn.checkLogin(data);
      if(bl)return;
      success(data);
    },function(response,err){
      var statusText = response.statusText;
      if(statusText == 'error'){
        layerFn.connectFailure();
        return;
      }else{
        layerFn.connectFailure();
      }
    },function(response,status){
      if(complete){
        complete(response,status);
      }
    });
  }
  function ajaxRequestGetError(url,params,beforeSend,success,error,complete){
    ajaxGet(url,params,function(request){
      if(beforeSend){
        beforeSend(request);
      }
    },function(data){
      var bl = layerFn.checkLogin(data);
      if(bl)return;
      success(data);
    },function(response,err){
      if(error){
        error(response,err);
      }
    },function(response,status){
      if(complete){
        complete(response,status);
      }
    });
  }
  //后面的两个参数error,complete是给带请求动画用的
  function ajaxRequestPost(url,params,beforeSend,success,error,complete){
    ajaxPost(url,params,function(request){
      if(beforeSend){
        beforeSend(request);
      }
    },function(data){
      success(data);
    },function(response,err){
      var resText = response.responseText;
      var statusText = response.statusText;
      if(statusText == 'error'){
        layerFn.connectFailure();
        return;
      }else{
        layerFn.alert('未知错误，稍后重试！',AppKey.code.code199);
        return;
      }
    },function(response,status){
      if(complete){
        complete(response,status);
      }
    });
  }
  //ajax的GET请求
  function ajaxGet(url,params,beforeSend,success,error,complete){
    ajaxOpt({
      url : url,
      params : params,
      beforeSend : function(request){
        if(beforeSend !=null && beforeSend != undefined && beforeSend != ''){
          beforeSend(request);
        }
      },
      success : function(data){
        success(data);
      },
      error : function(response,err){
        if(error !=null && error != undefined && error != ''){
          error(response,err);
        }
      },
      complete : function(response,status){
        if(complete !=null && complete != undefined && complete != ''){
          complete(response,status);
        }
      }
    });
  }
  //ajax的POST请求
  function ajaxPost(url,params,beforeSend,success,error,complete){
    ajaxOpt({
      type : 'POST',
      url : url,
      params : params,
      beforeSend : function(request){
        if(beforeSend !=null && beforeSend != undefined && beforeSend != ''){
          beforeSend(request);
        }
      },
      success : function(data){
        success(data);
      },
      error : function(response,err){
        if(error !=null && error != undefined && error != ''){
          error(response,err);
        }
      },
      complete : function(response,status){
        if(complete !=null && complete != undefined && complete != ''){
          complete(response,status);
        }
      }
    });
  }
  //若 type为空则是GET请求,用法:ajaxOpt({type:'POST'});
  function ajaxOpt(options){
    var type = options.type || 'GET';
    var url = options.url;
    var params = options.params || {};
    var beforeSend = options.beforeSend || null;
    var success = options.success;
    var error = options.error || null;
    var complete = options.complete || null;
    var contentType = 'application/x-www-form-urlencoded;charset=utf-8;';
    if('post' == type.toLowerCase()){
      contentType = 'multipart/form-data;charset=utf-8;';
    }
    $.ajax({
      type : type,
      url : urlPrefix + url,
      //xhrFields : {withCredentials: true},crossDomain : true,
      headers : {'accessToken': sessionStorage.getItem('accessToken') || ''},
      dataType : "json",
      data : params,
      crossDomain: true == !(document.all),
      beforeSend : function(request){
        if(beforeSend !=null && beforeSend != undefined && beforeSend != ''){
          beforeSend(request);
        }
      },
      success : function(data){
        if(success !=null && success != undefined && success != ''){
          success(data);
        }
      },
      error : function(response,err){
        if(error !=null && error != undefined && error != ''){
          error(response,err);
        }
      },
      statusCode : {
        403 : function(response) {
          layerFn.alert("无操作权限",AppKey.code.code401);
        },
        404 : function(response) {
          status404(response);
        },
        500 : function(){
          status500();
        },
        502 : function(response){
          layerFn.alert("网关代理出错,稍候重试");
        }
      },
      complete : function(response,status){
        if(complete !=null && complete != undefined && complete != ''){
          complete(response,status);
        }
        ajaxComplete(response.responseJSON);
      }
    });
  }
  function status404(response){
    var json = eval('('+ response.responseText +')');
    layerFn.alert("访问("+json.path+")路径不存在,你可以试试<a style='color:#1e9fff;' href='http://www.dwz.cloud' target='_blank'>引路者</a>解决找不到网页问题",AppKey.code.code199);
  }
  function status500(){
    layerFn.alert(AppKey.msg.msg204,AppKey.code.code204);
  }
  //鉴权是否有访问权限标识,若没有直接移除dom,仅适用于没有DataTable的页面且一进入就执行或初始化
  function ajaxComplete(json){
    try{}catch(e){}
  }
})(jQuery);